// assembly/widget/Initialization.hpp

#ifndef INITIALIZATION_HPP
#define INITIALIZATION_HPP

#include <QString>
#include <QDebug>
#include <QLoggingCategory>
#include "tool/Tool.hpp"
#include "store/struct/Basic.hpp"
#include "store/Huben.hpp"
#include "store/type/ActionWrapper.hpp"
#include "store/register/ActionManager.hpp"
#include "plugin/logger/FileSavePlugin.hpp"
#include "plugin/LoggingPlugin.hpp"
#include "plugin/logger/ConsoleLogReceiver.hpp"

/**
 * @brief 初始化类，负责应用启动时的初始化工作
 */
class Initialization {
public:
    /**
     * @brief 静态初始化函数
     */
    static void initialize() {

        // 注册 QtMsgType
        qRegisterMetaType<QtMsgType>("QtMsgType");

        Logger::installMessageHandler();

        auto consoleReceiver = new ConsoleLogReceiver();
        Logger::instance().addLogReceiver(consoleReceiver);

        // 注册插件
        FileSavePlugin *filePlugin = new FileSavePlugin("Logger.log");
        Huben::instance().registerPlugin(filePlugin);

        LoggingPlugin *loggingPlugin = new LoggingPlugin();
        Huben::instance().registerPlugin(loggingPlugin);

        // 创建 ActionManager，注册动作和变更处理函数
        ActionManager actionManager;

        Basic basic;


        // 替换为实际的 BeatEditor 目录路径
        // QString beatEditorPath = "/home/lc/Documents/1215/BeatEditor";
        // 例如：QString beatEditorPath = QString::fromUtf8("C:/中文路径/BeatEditor");

        // 将 basicData 写入到 Huben 的状态
        Huben::instance().setState(ActionWrapper::StateKey::Basic, QVariant::fromValue(Tool::ImportXML("", QDate::currentDate().toString("yyyy-MM-dd"))));
    }
};

#endif // INITIALIZATION_HPP
